home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-04 / bipl.zip / PROGS.ZIP / SING.ICN < prev    next >
Text File  |  1992-12-30  |  2KB  |  96 lines

  1. ############################################################################
  2. #
  3. #    File:     sing.icn
  4. #
  5. #    Subject:  Program to sing The Twelve Days of Christmas
  6. #
  7. #    Author:   Frank J. Lhota
  8. #
  9. #    Date:     September 14, 1990
  10. #
  11. ###########################################################################
  12. #  
  13. #     This program is an Icon adaptation of a SNOBOL program by Mike
  14. #  Shapiro in the book The SNOBOL4 Programming Language.  The procedure
  15. #  sing writes the lyrics to the song, "The Twelve Days of Christmas"
  16. #  to the singer parameter.  "singer" can be any file open for output,
  17. #  but it would be especially nice to send the lyrics to a speech
  18. #  synthesiser (perhaps via a pipe).  
  19. #
  20. #     The algorithm used can be adapted to other popular songs, such as
  21. #  "Old McDonald had a Farm".
  22. #
  23. #  Reference:
  24. #
  25. #     "The SNOBOL 4 Programming Language" by Griswold, Poage, and
  26. #  Polonsky, 2nd ed. Englewood Cliffs, N.J. Prentiss-Hall, Inc. 1971.
  27. #
  28. ############################################################################
  29.  
  30. procedure sing(singer)
  31.  
  32.     local which, and
  33.     static day, gift
  34.  
  35.     initial {
  36.     day := [
  37.         "first",
  38.         "second",
  39.         "third",
  40.         "fourth",
  41.         "fifth",
  42.         "sixth",
  43.         "seventh",
  44.         "eighth",
  45.         "ninth",
  46.         "tenth",
  47.         "eleventh",
  48.         "twelfth"]
  49.  
  50.     gift := [
  51.         "twelve lords a'leaping,",
  52.         "eleven ladies dancing,",
  53.         "ten pipers piping,",
  54.         "nine drummers drumming,",
  55.         "eight maids a'milking,",
  56.         "seven swans a'swimming,",
  57.         "six geese a'laying,",
  58.         "five golden rings,",
  59.         "four colly birds,",
  60.         "three french hens,",
  61.         "two turtle doves,",
  62.         "a partridge in a pear tree."]
  63.     }
  64.  
  65.     every which := 1 to 12 do {
  66.     write (singer)    # Take a breath
  67.     write (singer, "On the ", day [which], " day of Christmas,")
  68.     write (singer, "my true love gave to me,")
  69.     every write (singer, !(gift[-which : 0]))
  70.  
  71.     if (/and := "and ") then gift[-1] := and || gift[-1]
  72.     }
  73.  
  74.     #
  75.     # Reset gift[-1] in case sing is called again.
  76.     #
  77.  
  78.     gift[-1] ?:= (=and & tab (0))
  79.  
  80.     return
  81.     
  82. end
  83.  
  84. ############################################################################
  85.  
  86. procedure main ()
  87.  
  88.     #
  89.     # Try out sing procedure with standard output.
  90.     #
  91.     
  92.     sing(&output)
  93.  
  94. end
  95.